package com.xgst.lib.utils
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.disposables.Disposable
import java.text.SimpleDateFormat
import java.util.*
import java.util.concurrent.TimeUnit

class TimeUtils {
    companion object{

        fun getCurrentTime(format : String = "yyyy-MM-dd HH:mm:ss"):String{
            return SimpleDateFormat(format).format(Date())
        }

        fun getCurrentWeek():String{
            val c = Calendar.getInstance();
            c.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
            var mWay = c.get(Calendar.DAY_OF_WEEK)
            when(mWay){
                1 -> return "日"
                2 -> return "一"
                3 -> return "二"
                4 -> return "三"
                5 -> return "四"
                6 -> return "五"
                7 -> return "六"
                else -> return "*"
            }
        }

        fun countDownOneTime(milliSeconds: Long, listener: ()-> Unit):Disposable {
            val disposable = Observable.interval(milliSeconds, TimeUnit.MILLISECONDS)
                .take(1)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe { aLong: Long? -> listener()}
            return disposable
        }

    }
}